package com.oracle.application.config;

import com.oracle.application.utils.RSAUtils;
import io.jsonwebtoken.*;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@ConfigurationProperties(prefix = "jwt")
@Data
@Component
public class JwtConfig {

    private String publicKey;

    public void verifyToken(String token)throws ExpiredJwtException,UnsupportedJwtException,MalformedJwtException,SignatureException,IllegalArgumentException{
        try {
          Jwts.parser().setSigningKey(RSAUtils.publicKeyToPublic(publicKey)).parseClaimsJws(token);
        } catch (ExpiredJwtException e) {
           throw e;
        } catch (UnsupportedJwtException e) {
            throw e;
        } catch (MalformedJwtException e) {
            throw e;
        } catch (SignatureException e) {
            throw e;
        } catch (IllegalArgumentException e) {
            throw e;
        }

    }
}
